<?php
/**
 * 1626cms 网银在线插件
 * ============================================================================
 * 版权所有: 1626网络，并保留所有权利。
 * 网站地址: http://www.1626.com；
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用；不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
*/

 if(!defined('IN_QISHI'))
 {
 	die('Access Denied!');
 }
//生成支付代码
function get_code($order, $payment)
    {
	global $_CFG;
	if (!is_array($order) ||!is_array($payment))  return false;
	if (!intval($order['v_amount']) || $order['v_amount']+0==0)  return false;
        $data_mid  = trim($payment['partnerid']);//商户编号
        $data_oid   = $order['oid'];//订单号
        $data_amount  = $order['v_amount']; //支付金额  
        $data_moneytype  = 'CNY';//币种
        $data_key  = trim($payment['ytauthkey']);//MD5密钥
        $data_url = $order['v_url'];//返回url,地址应为绝对路径,带有http协议
		$data_remark1 = $order['remark1'];//备注1
        $MD5KEY =$data_amount.$data_moneytype.$data_oid.$data_mid.$data_url.$data_key;
        $MD5KEY = strtoupper(md5($MD5KEY)); //md5加密拼凑串,注意顺序不能变
        $def_url  = '<form name="E_FORM"  method="post" action="https://pay3.chinabank.com.cn/PayGate" target="_blank">';
        $def_url .= "<input type=HIDDEN name='v_mid' value='".$data_mid."'>";//商户编号
        $def_url .= "<input type=HIDDEN name='v_oid' value='".$data_oid."'>";//订单号
        $def_url .= "<input type=HIDDEN name='v_amount' value='".$data_amount."'>"; //支付金额  
        $def_url .= "<input type=HIDDEN name='v_moneytype'  value='".$data_moneytype."'>";//币种
        $def_url .= "<input type=HIDDEN name='v_url'  value='".$data_url."'>";//返回url,地址应为绝对路径,带有http协议
        $def_url .= "<input type=HIDDEN name='v_md5info' value='".$MD5KEY."'>"; //md5加密拼凑串
        $def_url .= "<input type=HIDDEN name='remark1' value='".$remark1."'>";//备注
        $def_url .= "</form>";
		$def_url .= "<input type=\"image\" name=\"imageField\" src='".$_CFG['site_template']."images/payment.gif'  onclick=\"document.E_FORM.submit();openLayer('op1','tis')\"/>";
        return $def_url;
    }
/**
 * 响应操作
*/
function respond()
{
$payment        = get_payment_info('chinabank');
$v_oid          = trim($_POST['v_oid']);
$v_pmode        = trim($_POST['v_pmode']);
$v_pstatus      = trim($_POST['v_pstatus']);
$v_pstring      = trim($_POST['v_pstring']);
$v_amount       = trim($_POST['v_amount']);
$v_moneytype    = trim($_POST['v_moneytype']);
$remark1        = trim($_POST['remark1']);
$remark2        = trim($_POST['remark2']);
$v_md5str       = trim($_POST['v_md5str']);
/**
* 重新计算md5的值
*/
$key = $payment['ytauthkey'];

$md5string=strtoupper(md5($v_oid.$v_pstatus.$v_amount.$v_moneytype.$key));
 /* 检查秘钥是否正确 */
if ($v_md5str==$md5string)
{
if ($v_pstatus == '20')
{
/* 改变订单状态 */
if (!order_paid($v_oid)) return false;
return true;
}
}
else
{
return false;
}
}
//获取安装字符
function get_install_code()
{
$payment_info=get_payment_one("chinabank");
$html_str="<table width=\"800\" border=\"0\" cellspacing=\"5\" cellpadding=\"1\" style=\" margin-bottom:3px;\">";
$html_str.="<tr>";
$html_str.="<td width=\"243\" align=\"right\">支付方式简短描述：</td>";
$html_str.="<td width=\"538\">";
$html_str.="<input name=\"p_introduction\" type=\"text\"  class=\"article_text_long\" maxlength=\"40\" value=\"".$payment_info['p_introduction']."\" />";
$html_str.="<input name=\"act\" type=\"hidden\" id=\"act\" value=\"save_install_payment\" />";
$html_str.="<input name=\"p_install\" type=\"hidden\"  value='2' />";
$html_str.="<input name=\"id\" type=\"hidden\"  value='".$payment_info['id']."'/>";
$html_str.="</td>";
$html_str.="</tr>";
$html_str.="<tr>";
$html_str.="<td width=\"243\" align=\"right\">详细描述：</td>";
$html_str.="<td width=\"538\"><textarea name=\"notes\" class=\"article_text_long\"  style=\"height:100px;\" >".$payment_info['notes']."</textarea></td>";
$html_str.="</tr>";
$html_str.="<tr>";
$html_str.="<td width=\"243\" align=\"right\">商户编号：</td>";
$html_str.="<td width=\"538\">";
$html_str.="<input name=\"partnerid\" type=\"text\"  class=\"article_text_long\" maxlength=\"20\" value='' />";
$html_str.="</td>";
$html_str.="</tr>";
$html_str.="<tr>";
$html_str.="<td width=\"243\" align=\"right\">MD5 密钥：</td>";
$html_str.="<td width=\"538\">";
$html_str.="<input name=\"ytauthkey\" type=\"text\"  class=\"article_text_long\" maxlength=\"60\" value='' />";
$html_str.="</td>";
$html_str.="</tr>";
$html_str.="<tr>";
$html_str.="<td width=\"243\" align=\"right\">手续费：</td>";
$html_str.="<td width=\"538\"><input name=\"fee\" type=\"text\"  class=\"article_text\"  value='0' maxlength=\"5\" onkeyup=\"if(isNaN(value))execCommand('undo')\" onafterpaste=\"if(isNaN(value))execCommand('undo')\" />%</td>";
$html_str.="</tr>";
$html_str.="<tr>";
$html_str.="<td width=\"243\" align=\"right\">排序：</td>";
$html_str.="<td width=\"538\"><input name=\"listorder\" type=\"text\"  class=\"article_text\"  value='50'  onkeyup=\"if(event.keyCode !=37 && event.keyCode != 39) value=value.replace(/\D/g,'');\" onbeforepaste=\"clipboardData.setData('text',clipboardData.getData('text').replace(/\D/g,''))\" maxlength=\"3\"/> 数字越大越靠前</td>";
$html_str.="</tr>";
$html_str.="</table>";
return $html_str;
}
//获取修改字符
function get_edit_code()
{
$payment_info=get_payment_one("chinabank");
$html_str="<table width=\"800\" border=\"0\" cellspacing=\"5\" cellpadding=\"1\" style=\" margin-bottom:3px;\">";
$html_str.="<tr>";
$html_str.="<td width=\"243\" align=\"right\">支付方式简短描述：</td>";
$html_str.="<td width=\"538\">";
$html_str.="<input name=\"p_introduction\" type=\"text\"  class=\"article_text_long\" maxlength=\"40\" value=\"".$payment_info['p_introduction']."\" />";
$html_str.="<input name=\"act\" type=\"hidden\" id=\"act\" value=\"save_install_payment\" />";
$html_str.="<input name=\"p_install\" type=\"hidden\"  value='2' />";
$html_str.="<input name=\"id\" type=\"hidden\"  value='".$payment_info['id']."'/>";
$html_str.="</td>";
$html_str.="</tr>";
$html_str.="<tr>";
$html_str.="<td width=\"243\" align=\"right\">详细描述：</td>";
$html_str.="<td width=\"538\"><textarea name=\"notes\" class=\"article_text_long\"  style=\"height:100px;\" >".$payment_info['notes']."</textarea></td>";
$html_str.="</tr>";
$html_str.="<tr>";
$html_str.="<td width=\"243\" align=\"right\">商户编号：</td>";
$html_str.="<td width=\"538\">";
$html_str.="<input name=\"partnerid\" type=\"text\"  class=\"article_text_long\" maxlength=\"20\" value='".$payment_info['partnerid']."' />";
$html_str.="</td>";
$html_str.="</tr>";
$html_str.="<tr>";
$html_str.="<td width=\"243\" align=\"right\">MD5 密钥：</td>";
$html_str.="<td width=\"538\">";
$html_str.="<input name=\"ytauthkey\" type=\"text\"  class=\"article_text_long\" maxlength=\"60\" value='".$payment_info['ytauthkey']."' />";
$html_str.="</td>";
$html_str.="</tr>";
$html_str.="<tr>";
$html_str.="<td width=\"243\" align=\"right\">手续费：</td>";
$html_str.="<td width=\"538\"><input name=\"fee\" type=\"text\"  class=\"article_text\"  value='".$payment_info['fee']."' maxlength=\"5\" onkeyup=\"if(isNaN(value))execCommand('undo')\" onafterpaste=\"if(isNaN(value))execCommand('undo')\" />%</td>";
$html_str.="</tr>";
$html_str.="<tr>";
$html_str.="<td width=\"243\" align=\"right\">排序：</td>";
$html_str.="<td width=\"538\"><input name=\"listorder\" type=\"text\"  class=\"article_text\"  value='".$payment_info['listorder']."'  onkeyup=\"if(event.keyCode !=37 && event.keyCode != 39) value=value.replace(/\D/g,'');\" onbeforepaste=\"clipboardData.setData('text',clipboardData.getData('text').replace(/\D/g,''))\" maxlength=\"3\"/> 数字越大越靠前</td>";
$html_str.="</tr>";
$html_str.="</table>";
return $html_str;
}
?>